package com.shengsiyuan.netty.firstexample;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * @author 荀彧 2021/1/5
 */
public class TestServerInitializer extends ChannelInitializer<SocketChannel> {

    /**
     * 连接被创建之后，就会执行这个方法。是一个回调方法
     * @param ch
     * @throws Exception
     */
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 里面有很多的channelHandler，相当于拦截器
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast("httpServerCodec",new HttpServerCodec());
        pipeline.addLast("testHttpServerHandler",new TestHttpServerHandler());
    }

}

